package com.binary;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
 * 二进制数据的读写操作
 * 各种数据类型的保存于于读取
 * 其中占字节大小
 * byte 1字节
 * short 2字节
 * int 4字节
 * long 8字节
 * float 4字节
 * double 8字节
 * 
 * 汉字 2字节
 * 字符 1个字节
 * 
 *  一个字节 = 8bit
 *  bit 是二进制位 01 组成
 *
 *
 * 
 * @author Administrator
 *
 */
public class DataoutPutDemo {
	public static void main(String[] args) throws IOException {
		 bin();
	}

	private static void bin() throws IOException, FileNotFoundException {
		String path = "C:" + File.separator + "BBB" + File.separator;
		String fileName = "aa.bin";
		File f = new File(path);

		if (!f.exists()) {
			f.mkdir();
		}

		File file = new File(path + fileName);
		if (!file.exists())
			file.createNewFile();

		DataOutputStream out = new DataOutputStream(new FileOutputStream(file,
				false));
		for (int i = 0; i < 100; i++) {

			out.writeByte(10);
			out.writeShort(10);
			out.writeInt(10);
			out.writeLong(10l);
			out.writeDouble(10d);
			out.writeByte(10);
			out.writeShort(10);
			out.writeInt(10);
			out.writeLong(10l);
			out.writeDouble(10d);
		}
		out.flush();
		out.close();
		System.out.println("ok");
	}

}
